<template>
	<view class="animated fadeIn faster">
		<view class="p-3">
			<view class="bg-fff rounded15 p-2 mb-2" v-for="note in list" :key="note.id">
				<view class="d-flex d-flex-between d-flex-middle mb-2">
					<text class="font26 color5c">{{note.updated_at}}</text>
					<text class="font26 colorred" @click="deleteNote(note.question.id)">删除</text>
				</view>
				<view class="mb-2 color666">{{note.content}}</view>
				<view class="bg-f2f2f2 p-2 d-flex rounded10" @click="goWatch(note.question)">
					<view class="optiona rounded5 d-flex d-flex-center d-flex-middle mr-1">{{note.question.type == 2?'判断':'选择'}}</view>
					<view class="d-flex-item text-clamp color5c">{{note.question.content}}</view>
				</view>
			</view>
			
		</view>
		<view class="load-more d-flex d-flex-center d-flex-column d-flex-middle">
			<image class="mb-2" v-if="loadingType == 2 && list.length == 0"
				src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/formal/images/empty.png"
				style="width: 198rpx;height: 128rpx;margin-top: 260rpx;"></image>
			<text>{{loadingType === 0 ? '上拉显示更多' : (loadingType === 1 ? '正在加载...' : '~ 没有更多数据了 ~')}}</text>
		</view>
		<!-- <view class="d-flex d-flex-center">
			<view class="bg-fff rounded60 d-flex d-flex-middle" style="padding: 20rpx 150rpx; color: #D43030;">
				<text class="iconfont icon-shanchu mr-1 font28"></text>
				<text>删除所有收藏</text>
			</view>
		</view> -->
	</view>
</template>
<script>
	import { userApi } from '@/http/userApi.js'
	export default {
		data() {
			return {
				loadingType:1,
				list:[]
			}
		},
		onReady() {
			this.getNoteList()
		},
		methods: {
			getNoteList(){
				let that = this
				uni.showLoading({
					title:'加载中...',
					mask:true
				})
				that.loadingType=1
				userApi.getNoteList().then((res)=>{
					uni.hideLoading()
					that.loadingType = 2
					console.log('my-note',res)
					that.list = res.data
				}).catch((e)=>{
					that.loadingType = 2
					uni.hideLoading()
				})
			},
			goWatch(error){
				error.user_answer = 'x'
				error.correct_answer = error.answer
				return uni.navigateTo({
					url: `/subPages/topic/topic?topic=${encodeURIComponent(JSON.stringify(error))}`
				})
			},
			deleteNote(noteId){
				let that = this
				uni.showLoading({
					title:'操作中...'
				})
				userApi.deleteNote(noteId).then((res)=>{
					uni.showToast({
						title:'删除成功！'
					})
					setTimeout(()=>{
						that.getNoteList()
					},1000)
					uni.hideLoading()
				}).catch((e)=>{
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style scoped>
.optiona{
	background-color: #FF8D1A;
	color: #fff;
	width: 60rpx;
	height: 40rpx;
	font-size: 24rpx;
}
</style>
